<?php
    if(!function_exists('upload'))
    {
        /**
        * 创建目标路径
        * 检查扩展名合法   
        * 
        * @param mixed $file $_FILES['name']
        * @param mixed $toDir  
        */
        function upload($file,$toDir,$desFileName =''){
            if(empty($file)){
                return false;
            }
            if(!file_exists($toDir)){
                if(!@mkdir($toDir,'0755',true)){
                    return false;
                }
            }
            $file_ext = getFileExt($file['name']);
            $valid_ext = C('validExt');
            if(is_array($valid_ext)){
                if(!in_array($file_ext,$valid_ext)){
                    return false;
                }
            }
            $tempName=$file["tmp_name"];

            $extend = pathinfo($file["name"]);
            $extend = strtolower($extend["extension"]);

            if($desFileName == ''){
                $desFileName = @date("Ymd_His_",time()).rand();
            }

            $newName = $desFileName.".".$extend;
            if(!copy($tempName,$toDir.$newName)){
                if(FW_DBUG){
                    alert('error 上传失败');
                }
                return false;
            }
            return $newName;
        }
    }
?>